package cn.edu.ahu.aircondition.modbus.service.dao;

import cn.edu.ahu.aircondition.modbus.service.entity.AirConSetEntity;
import cn.edu.ahu.aircondition.modbus.service.entity.AirConStatuWaterEntity;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.util.List;

/**
 *
 * Created by ahu on 2017/6/11.
 */
public class AirSetDao {
    private SessionFactory sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();

    /**
     * 根据deviceId获取状态信息
     * @return 设备状态信息
     */
    public List<AirConSetEntity> listAirConSet(){
        Transaction transaction = sessionFactory.getCurrentSession().getTransaction();
        transaction.begin();
        Session session = sessionFactory.getCurrentSession();
        //开始事务
        String queryString = "FROM AirConSetEntity";
        List<AirConSetEntity> list = session.createQuery(queryString,AirConSetEntity.class).getResultList();
        transaction.commit();
        session.close();
        return list;
    }

}
